﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Gencode.VECore;

namespace WF.VecDraw
{
    /// <summary>
    /// Interaction logic for ToolsWindow.xaml
    /// </summary>
    public partial class ToolsWindow : Window
    {
        public ToolsWindow()
        {
            InitializeComponent();
        }

		public double LeftOffset
		{
			get;
			set;
		}

		public double TopOffset
		{
			get;
			set;
		}

		private void SetTool(ToolType shapeType)
		{
            if (CanvasDocument.SelectedToolType != shapeType)
            {
                switch (CanvasDocument.SelectedToolType)
                {
                    case ToolType.SelectionTool:
                        btnGrab.Selected = false;
                        break;
                    case ToolType.Line:
                        btnLine.Selected = false;
                        break;
                    case ToolType.Rectangle:
                        btnBox.Selected = false;
                        break;
                    case ToolType.Ellipse:
                        btnCircle.Selected = false;
                        break;
                    case ToolType.Polygon:
                        btnPath.Selected = false;
                        break;
                    case ToolType.Curve:
                        btnCurve.Selected = false;
                        break;
                }

                CanvasDocument.SelectedToolType = shapeType;
            }
		}

		private void btnGrab_MouseUp(object sender, MouseButtonEventArgs e)
		{
			SetTool(Gencode.VECore.ToolType.SelectionTool);
			this.Owner.Focus();
		}

		private void btnLine_MouseUp(object sender, MouseButtonEventArgs e)
		{
			SetTool(Gencode.VECore.ToolType.Line);
			this.Owner.Focus();
		}

		private void btnBox_MouseUp(object sender, MouseButtonEventArgs e)
		{
			SetTool(Gencode.VECore.ToolType.Rectangle);
			this.Owner.Focus();
		}

		private void btnCircle_MouseUp(object sender, MouseButtonEventArgs e)
		{
			SetTool(Gencode.VECore.ToolType.Ellipse);
			this.Owner.Focus();
		}

		private void Window_LocationChanged(object sender, EventArgs e)
		{
			LeftOffset = Left - this.Owner.Left;
			TopOffset = Top - this.Owner.Top;
		}

        private void btnPath_MouseUp(object sender, MouseButtonEventArgs e)
        {
            SetTool(Gencode.VECore.ToolType.Polygon);
            this.Owner.Focus();
        }

        private void btnCurve_MouseUp(object sender, MouseButtonEventArgs e)
        {
            SetTool(Gencode.VECore.ToolType.Curve);
            this.Owner.Focus();
        }
    }
}
